package com.pureut.system.controller;

import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;

import com.pureut.system.domain.SysOfCode;
import com.pureut.system.service.ISysOfCodeService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.pureut.common.core.web.controller.BaseController;

import java.util.List;

/**
 * 编码生成配置
 *
 * @author hl
 */
@RestController
@RequestMapping("/ofcode")
public class SysOfCodeController extends BaseController{

    @Autowired
    private ISysOfCodeService sysOfCodeService;

    /**
     * 获取编码配置
     */
    @RequiresPermissions("system:ofcode:list")
    @GetMapping("/list")
    public TableDataInfo list(SysOfCode ofCode)
    {
        startPage();
        List<SysOfCode> list = sysOfCodeService.selectOfCodeList(ofCode);
        return getDataTable(list);
    }

    /**
     * 新增编码配置
     */
    @RequiresPermissions("system:ofcode:add")
    @Log(title = "编码配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SysOfCode sysOfCode) throws Exception {
        return toAjax(sysOfCodeService.ofCodeAdd(sysOfCode));
    }


    /**
     * 删除编码
     */
    @RequiresPermissions("system:ofcode:remove")
    @Log(title = "删除配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ofCodeId}")
    public AjaxResult remove(@PathVariable("ofCodeId") String ofCodeId) throws Exception {
        return toAjax(sysOfCodeService.deleteOfCodeById(ofCodeId));
    }


    /**
     * 根据编号获取详细信息
     */
    @RequiresPermissions("system:ofcode:query")
    @GetMapping(value = "/{ofCodeId}")
    public SysOfCode getInfo(@PathVariable Long ofCodeId)
    {
        return sysOfCodeService.selectofCodeById(ofCodeId);
    }


    /**
     * 修改配置
     */
    @RequiresPermissions("system:user:edit")
    @Log(title = "修改配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysOfCode sysOfCode) throws Exception {
        return toAjax(sysOfCodeService.updateOfEdit(sysOfCode));
    }


    /**
     * 获取下拉
     */
    @GetMapping("/listThe")
    public AjaxResult listThe()
    {
        AjaxResult ajax = AjaxResult.success();
        ajax.put("theDrop", sysOfCodeService.selectOfCodeListThe());
        return ajax;
    }

}
